﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Library1;

namespace NewBootTrap
{
    public partial class FormMain : Form
    {        
        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            UpdateApplication updateApplication = new UpdateApplication();             

            //Update real main client update program
            updateApplication.ClientDirectoryPath = Application.StartupPath;
            updateApplication.ServerDirectoryName = "Programs";
            if (updateApplication.GetNumberToUpdate() > 0)
            {
                updateApplication.Download();                
            }
            
            //Update normal 
            UpdateServiceTruyenNhan updateServiceTN = new UpdateServiceTruyenNhan();
            int numberUpdate = updateServiceTN.GetNumberToUpdate();               
            if (numberUpdate > 0)
            {
                if (MessageBox.Show("Install path : " + updateApplication.ClientDirectoryPath + "\r\n" + "An update is available ! ( " + numberUpdate + " Files updates ) \r\nDou you want to update now ?", "Update", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    //Start the real updater
                    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                    psi.FileName = Application.StartupPath + "\\ClientTest.exe";
                    psi.UseShellExecute = true;
                    psi.WorkingDirectory = Application.StartupPath;

                    System.Diagnostics.Process.Start(psi);
                    Application.Exit();
                }                    
            }
           
           
            Application.Exit();

            
            
        }                    
    }
}
